import { _decorator, Component, Node, tween, v3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('Guest')
export class Guest extends Component {
    private tweenRight: any = null;
    private tweenLeft: any = null;
    start() {
        this.moveAction();
    }

    protected onEnable(): void {
        this.moveAction();
    }

    moveAction() {
        this.node.setScale(v3(1.4, 1.4, 1.4));
        this.tweenRight = tween(this.node)
            .by(25, { position: v3(500, 0, 0) })
            .call(() => {
                this.node.setScale(v3(-1.4, 1.4, 1.4));
                this.tweenLeft = tween(this.node)
                    .by(25, { position: v3(-500, 0, 0) })
                    .call(() => {
                        this.moveAction();
                    })
                    .start();
            })
            .start();
    }

    protected onDisable(): void {
        if (this.tweenRight) {
            this.tweenRight.stop();
        }
        if (this.tweenLeft) {
            this.tweenLeft.stop();
        }
    }

    update(deltaTime: number) {
        
    }
}


